// 异步钩子 -- 并发promise
class AsyncParallelHook {
  // args => ['name']
  constructor(args) {
    this.tasks = [];
  }
  tapPromise(name, task) {
    this.tasks.push(task);
  }
  promise(...args) {
    let tasks = this.tasks.map((task) => task(...args));
    return Promise.all(tasks);
  }
}

let hook = new AsyncParallelHook(["name"]);

hook.tapPromise("node", (data) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log("前端小溪(" + data + ") --- 学习node");
      resolve();
    }, 1000);
  });
});
hook.tapPromise("webpack", (data) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log("前端小溪(" + data + ") --- 学习webpack");
      resolve();
    }, 2000);
  });
});

hook.promise("xiaoxi").then(() => {
  console.log("结束");
});
